home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 109_01.zip / DEL.C < prev    next >
Text File  |  1993-06-26  |  5KB  |  105 lines

  1. /*--------- DEL -- Version 1.1 --- 06 MAR 80 -- BDS C v1.2 ---------*/
  2. /*                                                                  */
  3. /*  DEL is a directory maintenance utility that provides a means    */
  4. /*  for selectively erasing files from a CP/M disk directory.       */
  5. /*  It is safer to use than the standard CP/M command ERA because   */
  6. /*  the user must confirm a deletion by answering a prompt of the   */
  7. /*  form                                                            */
  8. /*                                                                  */
  9. /*        DELETE FILE .... ? -- (Y/N/^C):                           */
  10. /*                                                                  */
  11. /*  If the response made to the prompt is "y" (upper or lower       */
  12. /*  lower case), DEL deletes the file.  If the response is any-     */
  13. /*  thing else, DEL retains the file.  A response of control-C      */
  14. /*  (^C) terminates DEL.  All other responses cause DEL to con-     */
  15. /*  tinue with the directory scan.                                  */
  16. /*                                                                  */
  17. /*  The execution syntax for DEL is the same as ERA, that is,       */
  18. /*                                                                  */
  19. /*       DEL <afn>                                                  */
  20. /*                                                                  */
  21. /*  where <afn> is a CP/M ambiguous file name.  The syntax for an   */
  22. /*  <afn> is                                                        */
  23. /*                                                                  */
  24. /*       <afn> = [<drv>:]{<file> |*}.{<type> | *}                   */
  25. /*                                                                  */
  26. /*       <drv> is a drive designator (A, B, C, or D).               */
  27. /*       <file> is a one-to-eight-character file name.              */
  28. /*       <type> is a zero-to-three-character file type.             */
  29. /*                                                                  */
  30. /*  As usual [ ... ] indicates an optional parameter and            */
  31. /*  { ... | ... } indicates that a choice of parameter is to be     */
  32. /*  made.  The question mark (?) is allowed as a wild-card          */
  33. /*  character in the <file> and <type> parameters.                  */
  34. /*                                                                  */
  35. /*------------------------------------------------------------------*/
  36.  
  37. #define     FIRST       17 
  38. #define     NEXT        18 
  39. #define     DELETE      19 
  40. #define     DRIVE       25 
  41. #define     ALL         255 
  42. #define     STDFCB      0x005C 
  43. #define     STDBFR      0x0080 
  44.  
  45. main()
  46.     {
  47.     char i, j, c, rq, rtn, skip, skp;
  48.     char *arg, *dirp, file[15], fcb[33];
  49.     int  lns, chrs;
  50.     /* Move the standard FCB to a safe place. */
  51.     movblk(STDFCB, fcb, 32);
  52.     fcb[32] = '\0';
  53.     /* If files are to be deleted on a different drive, */
  54.     /* make allowance for this.                         */
  55.     arg = STDBFR;
  56.     if (arg[3] == ':') file[0] = arg[2];
  57.     else file[0] = 'A' + bdos(DRIVE, 0);
  58.     file[1] = ':';
  59.     /* Initialize counters used to suppress repeating */
  60.     /* prompt on directory rescan.                    */
  61.     skip = skp = 0;
  62.     /* End of initialization  -- start of main loop.   */
  63.     /* BDOS calls bdos(FIRST, fcb) and bdos(NEXT, fcb) */
  64.     /* cause directory scans for match with the <afn>. */
  65.     rq = FIRST;
  66.     while ((rtn = bdos(rq, fcb)) != ALL)
  67.         {
  68.         rq = NEXT;
  69.         /* Skip over previously scanned but undeleted entries. */
  70.         if (++skp <= skip) continue;
  71.         /* Point to directory entry matching <afn> in STDBFR. */
  72.         dirp = STDBFR + ((rtn & 3) << 5);
  73.         /* Get file name from directory entry. */
  74.         i = 1;
  75.         for (j = 1; (j <= 8) && ((c = dirp[j]) != ' '); ++j)
  76.             {
  77.             file[++i] = c;
  78.             }
  79.         file[++i] = '.';
  80.         for (j = 9; (j <= 11) && ((c = dirp[j]) != ' '); ++j)
  81.             {
  82.             file[++i] = c;
  83.             }
  84.         file[++i] = '\0';
  85.         /* Prompt for permission to delete. */
  86.         printf("\nDELETE FILE %s? -- (Y/N/^C): ", file);
  87.         if (toupper(getchar()) == 'Y')
  88.             {
  89.             /* Permission granted -- delete file and */
  90.             /* request rescan of directory.          */
  91.             unlink(file);
  92.             rq = FIRST;
  93.             skp = 0;
  94.             }
  95.         else
  96.             {
  97.             /* Permission denied -- retain file and continue scan.   */
  98.             /* Note additional entry to be skipped if rescan occurs. */
  99.             ++skip;
  100.             }
  101.         }
  102.         /* End of main loop -- directory scan completed. */
  103.         puts("\nDONE");
  104.     }
  105.